var express = require('express');
var router = express.Router();
let mongoose = require('mongoose');
let jsonwebtoken = require('jsonwebtoken')
require('../util/authConfig')

//解密后端程序
router.post('/getUserAndErr', async function (req, resp) {
  //获取请求头中的token数据
  let auth = req.header('Authorization');
  let token = auth.replace('Bearer ', '');
  // userObj为student信息（全）
  let userObj = jsonwebtoken.verify(token, 'star').user;
  // 搜索已做试卷
  let re = await mongoose.model('errorsModel').find({
    studentId: userObj._id
  }).populate({
    path: 'exerciseId',
    populate: {
      path: 'pointId'
    }
  })
  if (re) {
    resp.send({
      code: 1,
      massage: '获取错题信息成功！',
      data: re
    });

  } else {
    resp.send({
      code: 2,
      massage: '获取错题信息失败！',
    });

  }
});


module.exports = router;